﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.Design;

namespace class11_数组遍历操作
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //遍历数组，使用foreach语句获得数组中的每个元素

            int[] gui ={ 1,2,3,4 };
            foreach (int it in gui)
            {
                Console.WriteLine(it);
                Console.WriteLine();
            }
          


            int[,] poo = { { 1, 2, 3 }, { 2, 3, 4 }, { 3, 4, 5 }, { 4, 5, 6 } };
            foreach (int i in poo)
            {

                Console.WriteLine(i);
                Console.WriteLine();
            }



            //test:计算数组元素总和
            int[] gy = { 22, 34, 76, 85, 24, 79 };
            int sum = 0;
            Console.WriteLine("该数组全部元素为：");
            foreach(int h in gy)
            {
                
                Console.WriteLine(h+" ");

                sum = sum + h;
            }

            Console.WriteLine("数组元素之和为：");
            Console.WriteLine(sum);




            //text2:找出数组中元素最大值并输出

            int[] juo = { 2, 5, 9, 34, 4, 7 };
            int o = 0;
            int max = 0;
            foreach(int k in juo)
            {
               
                if (k> max) 
                {
                    max = k;
                }
                
            }
            Console.WriteLine(max);
        }
    }
}
